var gdybProduct = {
    index: 0,
    selected: [],
    currTrIndex: -1,
    getwd: { "01": "北风", "02": "东北风", "03": "东风", "04": "东南风", "05": "南风", "06": "西南风", "07": "西风", "08": "西北风", "09": "转" },
    aboutCloud: ["晴", "晴间多云", "多云间晴", "晴转多云", "晴转阴", "多云", "多云间晴", "多云转晴", "多云转晴有扬沙", "多云间阴", "多云转阴", "阴", "阴间多云", "阴转多云", "阴转晴"],
    aboutRain: ["阴有阵雨", "阴有雷阵雨", "阴", "雷阵雨", "阴有零星小雨", "阴有小雨", "零星小雨", "小雨", "小到中雨", "中雨", "中到大雨", "大雨", "大到暴雨", "暴雨", "大暴雨", "特大暴雨",
        "暴雨转阴", "暴雨转小雨", "阴有阵雨转多云", "阴有雷阵雨转多云", "阴有小雨转多云", "晴转小雨", "晴转中雨", "晴转阴有雷阵雨", "晴转阴局部有零星小雨", "多云转阵雨", "多云转阴有阵雨",
        "多云转阴有雷阵雨", "多云转阴有中雨", "多云局部有阵雨", "多云转雷阵雨", "多云转中雨", "阴转大雨", "阴转阵雨", "阴转小雨", "阴转中雨", "阴转大雨", "阴转暴雨", "雨", "阵雨",
        "阵雨转阴", "阵雨转多云", "阵雨转晴", "雷阵雨", "雷阵雨转中雨", "雷阵雨转多云", "雷阵雨转阴", "雷阵雨转晴", "冰雹", "小雨转晴", "小雨转多云", "小雨转阴", "小雨转中雨",
        "小雨转大雨", "小雨转暴雨", "中雨转大雨", "中雨转小雨", "中雨转阴", "中雨转多云", "中雨转晴", "大雨转中雨", "大雨转小雨", "大雨转阴", "大雨转多云", "大雨转晴"
    ],
    aboutSnow: ["零星小雪", "雨夹雪", "小雨夹雪", "雪", "阵雪", "小雪", "小到中雪", "中雪", "中到大雪", "大雪", "大到暴雪", "暴雪", "大暴雪"],
    aboutOther: ["雾", "轻雾", "轻雾转多云", "大雾", "浓雾", "轻霜冻", "霜冻", "冰冻", "冻雨", "浮尘", "扬沙", "沙尘暴", "强沙尘暴", "短时大风", "霾"],
    getwp: {
        "01": "晴",
        "02": "多云",
        "03": "阴",
        "04": "小雨",
        "05": "阵雨",
        "06": "小到中雨",
        "07": "中雨",
        "08": "中阵雨",
        "09": "大雨",
        "10": "大阵雨",
        "11": "暴雨",
        "12": "大到暴雨",
        "13": "大暴雨",
        "14": "特大暴雨"
    },
    getrain: { "01": "5%", "02": "10%", "03": "20%", "04": "30%", "05": "40%", "06": "60%", "07": "70%" },
    getws: {
        "01": "1-2级",
        "02": "2-3级",
        "03": "3-4级",
        "04": "4-5级",
        "05": "5-6级",
        "06": "6-7级",
        "07": "7-8级",
        "08": "8-9级",
        "09": "9-10级",
        "10": "10-11级",
        "11": "11-12级",
        "12": "12-13级",
        "13": "13-14级"
    },
    stationName: "天 津 市 区,蓟  州,宝  坻,武  清,宁  河,静  海,北  辰,西  青,津  南,东  丽,滨 海 新 区,渤  海",
    getws2: ["", "", "", "阵风6级", "阵风7级", "阵风8级", "阵风9级", "阵风10级", "阵风11级", "阵风12级", "阵风13级", "阵风14级", "阵风15级"],
    initJson: "",
    productInfo: null,
    init: function () {
        this.productInfo = $(".task-menu-list li.active").data('product');
        this.initWithHeight();
        this.initData();
        this.bindEvents();
    },
    initData: function () {
        var fortime = this.productInfo.fortime;
        $(".single_time").each(function () {
            if ($(this).text() == fortime) {
                $(this).addClass("single_time_click");
                return false;
            }
        });
        var params = {
            "product_id": this.productInfo.productId,
            "fortime": fortime,
            "queryTime": new Date().format('yyyy-MM-dd 00:00:00')
        }
        loading.add('.cafe-container');
        $.getJSON(api.internal.common.getProductDetail, params, function (res) {
            loading.remove();
            gdybProduct.cleanTable()
            if (res.isSuccess && JSON.stringify(res.data) != "{}") {
                var jsonStr = JSON.parse(res.data.data.content);
				debugger
                gdybProduct.showData(jsonStr);
                gdybProduct.initJson = res.data.data.content;
            } else {
                gdybProduct.ajaxTable();
            }
        })
    },
    cleanTable: function () {
        var that = this;
        $(".n-single-table tr").remove();
        var str = "";
        if ($(".single_time_click").attr("fortimeid") == "06:00") {
            str = that.getTr(0, ["天气现象", "降水概率", "风向", "风速"]);
            str += that.getTr(1, ["天气现象", "降水概率", "风向", "风速", "高温", "最小相对湿度"]);
            str += that.getTr(2, ["天气现象", "降水概率", "风向", "风速"]);
            str += that.getTr(3, ["天气现象", "降水概率", "风向", "风速", "低温", "最大相对湿度"]);
            str += that.getTr(4, ["天气现象", "降水概率", "风向", "风速", "高温"]);
            str += that.getTr(5, ["天气现象", "降水概率", "风向", "风速", "低温"]);
        } else if ($(".single_time_click").attr("fortimeid") == "11:00") {
            str = that.getTr(0, ["天气现象", "降水概率", "风向", "风速", "高温", "最小相对湿度"]);
            str += that.getTr(1, ["天气现象", "降水概率", "风向", "风速"]);
            str += that.getTr(2, ["天气现象", "降水概率", "风向", "风速", "低温", "最大相对湿度"]);
            str += that.getTr(3, ["天气现象", "降水概率", "风向", "风速", "高温", "最小相对湿度"]);
            str += that.getTr(4, ["天气现象", "降水概率", "风向", "风速", "低温"]);
            str += that.getTr(5, ["天气现象", "降水概率", "风向", "风速", "高温"]);
            str += that.getTr(6, ["天气现象", "降水概率", "风向", "风速", "低温"]);
            str += that.getTr(7, ["天气现象", "降水概率", "风向", "风速", "高温"]);
        } else {
            str = that.getTr(0, ["天气现象", "降水概率", "风向", "风速"]);
            str += that.getTr(1, ["天气现象", "降水概率", "风向", "风速", "低温", "最大相对湿度"]);
            str += that.getTr(2, ["天气现象", "降水概率", "风向", "风速"]);
            str += that.getTr(3, ["天气现象", "降水概率", "风向", "风速", "高温", "最小相对湿度"]);
            str += that.getTr(4, ["天气现象", "降水概率", "风向", "风速", "低温"]);
            str += that.getTr(5, ["天气现象", "降水概率", "风向", "风速", "高温"]);
            str += that.getTr(6, ["天气现象", "降水概率", "风向", "风速", "低温"]);
            str += that.getTr(7, ["天气现象", "降水概率", "风向", "风速", "高温"]);
            str += that.getTr(8, ["天气现象", "降水概率", "风向", "风速", "高温", "低温"]);
            str += that.getTr(9, ["天气现象", "降水概率", "风向", "风速", "高温", "低温"]);
            str += that.getTr(10, ["天气现象", "降水概率", "风向", "风速", "高温", "低温"]);
            str += that.getTr(11, ["天气现象", "降水概率", "风向", "风速", "高温", "低温"]);
        }
        $(".n-single-table").append(str);
    },
    ajaxTable: function () {
        gdybProduct.cleanTable();
        loading.add('.cafe-container');
        $.post(api.external.initData, {
            product_id: this.productInfo.productId,
            fortime: $(".single_time_click").attr("fortimeid"),
            forecaster_id: $("#userInfo").data('info').smuser.forecasterId
        }, function (result) {
            loading.remove();
            if (result.params.initData) {
                var jsonStr = JSON.parse(result.params.initData);
                gdybProduct.showData(jsonStr);
                gdybProduct.initJson = result.params.initData;
            }
        }, 'json');
    },
    showData: function (jsonStr) {
        var that = this;
		var fortimeid = $(".single_time_click").attr("fortimeid");
        for (var cnt in jsonStr.tempData.curTagData) {
            if (cnt.substr(0, 1) == "h") {
                if (jsonStr.tempData.curTagData[cnt] != undefined && jsonStr.tempData.curTagData[cnt].val != "") {
                    jsonStr.tempData.curTagData[cnt].val = eval(jsonStr.tempData.curTagData[cnt].val);
                    for (var i = 0; i < jsonStr.tempData.curTagData[cnt].val.length; i++) {
                        var str = cnt.substr(9);
                        if (str == "yb03") {
                            $("." + str + "_0_" + i).html(jsonStr.tempData.curTagData[cnt].val[i][0]);
                        }
                        //debugger
                        $("#" + str + "_1_" + i).html(jsonStr.tempData.curTagData[cnt].val[i][1]).attr('title',jsonStr.tempData.curTagData[cnt].val[i][1]);
                        $("#" + str + "_2_" + i).html(weatherUtil.getVal(jsonStr.tempData.curTagData[cnt].val[i][1]));
                        $("#" + str + "_3_" + i).html(WindUtil.coverWindDesc(jsonStr.tempData.curTagData[cnt].val[i][3])).attr('title',WindUtil.coverWindDesc(jsonStr.tempData.curTagData[cnt].val[i][3]));
                        $("#" + str + "_4_" + i).html(jsonStr.tempData.curTagData[cnt].val[i][4]);
                        $("#" + str + "_5_" + i).html(jsonStr.tempData.curTagData[cnt].val[i][5]);
						var rh = jsonStr.tempData.curTagData[cnt].val[i][6];
						if (fortimeid == "11:00"){
							if(i==0 || i==2 || i==3){
								if (rh) rh = Math.round(rh.replace('%', '')) + '%';
								$("#" + str + "_6_" + i).html(rh);
							}else{
								if (rh){
									$("#" + str + "_6_" + i).html(rh.replace("%",""));
								}else{
									$("#" + str + "_6_" + i).html(rh);
								}
							}
						}else if(fortimeid == "06:00" || fortimeid == "17:00"){
							if(i==1 || i==3){
								if (rh) rh = Math.round(rh.replace('%', '')) + '%';
								$("#" + str + "_6_" + i).html(rh);
							}else{
								if (rh){
									$("#" + str + "_6_" + i).html(rh.replace("%",""));
								}else{
									$("#" + str + "_6_" + i).html(rh);
								}
							}
						}
                    }
                    var reg = /^(-?\d{1,2})(\.\d{1})?$/; //正则只能以为小数
                    $(".editTd div").off("click").on("click", function (ev) {
                        ev.preventDefault();
                        ev.stopPropagation();
                        var that = $(this);
                        that.currTrIndex = -1;
                        var tdHeight = that.parent()[0].clientHeight;
                        if (ev.ctrlKey) {
                            gdybProduct.clearPop2();
                            that.toggleClass("n-tabler-body-cell-editer-act");
                            return false;
                        } else {
                            gdybProduct.clearPop2();
                            var ev = ev || window.event;
                            var top = tdHeight;
                            var left = 0;
                            /*var menuWidth = 402;
                            var menuHeight = 126;*/
                            var menuWidth = 565;
                            var menuHeight = 270;
                            var tdLeft = that.parent()[0].offsetLeft;
                            var trWidth = that.parent().parent()[0].clientWidth;
                            var trTop = that.parent().parent()[0].offsetTop;
                            var tableHeight = that.parent().parent().parent()[0].clientHeight;
                            var tdWidth = that.parent()[0].clientWidth;
                            if (tdLeft + menuWidth > trWidth) {
                                left = -menuWidth - 8;
                            }

                            that.parent().parent().parent().parent()[0]
                            var initalVal = that.html();
                            if (that.attr("class").substr(0, 2) == "wp") {
                                var that = $(this);
                                if (that.find('input').length == 0) {
                                    if (initalVal == "--") {
                                        that.html("<input type=\"text\" id=\"tmpinput\" value=\"\" />");
                                    } else {
                                        that.html("<input type=\"text\" id=\"tmpinput\" value=\"" + initalVal + "\" />");
                                    }
                                    $('#tmpinput').select();
                                    $('#tmpinput').css('color', 'black');

                                    var str = '<div class="warning-analysis-container" style="top:' + top + 'px;left:' + left + 'px;display: block;">';
                                    str += '		<div class="analysistab">';
                                    str += '		<div class="analysis-tab cloud-tab analysis-tab-sel">云量相关</div>';
                                    str += '		<div class="analysis-tab rain-tab">雨相关</div>';
                                    str += '		<div class="analysis-tab snow-tab">雪相关</div>';
                                    str += '		<div class="analysis-tab other-tab">其他</div>';
                                    str += '	</div>';
                                    str += '	<div class="analysisbox autostat">';
                                    str += '		<div class="aboutDIV">';
                                    str += '<input type="text" class="cloudInput" />&nbsp;';
                                    str += '<input type="button" class="cloudOK" value="确定" />&nbsp;';
                                    str += '<input type="button" class="cloudCancel" value="取消" /></div>';
                                    str += '		<div class="cloudDiv">';
                                    for (var i = 0; i < gdybProduct.aboutCloud.length; i++) {
                                        str += '<div class="aboutItem1">' + gdybProduct.aboutCloud[i] + '</div>';
                                    }
                                    str += '		</div>';
                                    str += '	</div>';
                                    str += '	<div class="analysisbox radar">';
                                    str += '		<div class="aboutDIV"><input type="text" class="rainInput" />&nbsp;';
                                    str += '<input type="button" class="rainOK" value="确定" />&nbsp;';
                                    str += '<input type="button" class="rainCancel" value="取消" /></div>';
                                    str += '		<div class="rainDiv">';
                                    for (var i = 0; i < gdybProduct.aboutRain.length; i++) {
                                        str += '<div class="aboutItem2">' + gdybProduct.aboutRain[i] + '</div>';
                                    }
                                    str += '		</div>';
                                    str += '	</div>';
                                    str += '	<div class="analysisbox pic">';
                                    str += '		<div class="aboutDIV"><input type="text" class="snowInput" />&nbsp;';
                                    str += '<input type="button" class="snowOK" value="确定" />&nbsp;';
                                    str += '<input type="button" class="snowCancel" value="取消" /></div>';
                                    str += '		<div class="snowDiv">';
                                    for (var i = 0; i < gdybProduct.aboutSnow.length; i++) {
                                        str += '<div class="aboutItem3">' + gdybProduct.aboutSnow[i] + '</div>';
                                    }
                                    str += '		</div>';
                                    str += '	</div>';
                                    str += '	<div class="analysisbox linght">';
                                    str += '		<div class="aboutDIV"><input type="text" class="otherInput" />&nbsp;';
                                    str += '<input type="button" class="otherOK" value="确定" />&nbsp;';
                                    str += '<input type="button" class="otherCancel" value="取消" /></div>';
                                    str += '		<div class="otherDiv">';
                                    for (var i = 0; i < gdybProduct.aboutOther.length; i++) {
                                        str += '<div class="aboutItem4">' + gdybProduct.aboutOther[i] + '</div>';
                                    }
                                    str += '		</div>';
                                    str += '	</div>';
                                    str += '</div>';
                                    $(this).after(str);

                                    // 切换tab
                                    $(".analysis-tab").off("click").on("click", function () {
                                        var _this = $(this);
                                        if (_this.hasClass("analysis-tab-sel")) {
                                            return;
                                        } else {
                                            _this.addClass("analysis-tab-sel").siblings().removeClass("analysis-tab-sel");
                                            var $obj = $(".analysisbox");
                                            if (_this.hasClass("cloud-tab")) {
                                                $(".radar,.pic,.linght").hide();
                                                $(".autostat").show();
                                            } else if (_this.hasClass("rain-tab")) {
                                                $(".autostat,.pic,.linght").hide();
                                                $(".radar").show();
                                            } else if (_this.hasClass("snow-tab")) {
                                                $(".radar,.autostat,.linght").hide();
                                                $(".pic").show();
                                            } else {
                                                $(".radar,.pic,.autostat").hide();
                                                $(".linght").show();
                                            }
                                        }
                                    });
                                    $('.aboutItem1').off("click").on("click", function (ev) {
                                        ev.stopPropagation();
                                        $(".cloudInput").val($(this).html());
                                        $(this).addClass("active").siblings().removeClass("active")
                                    });
                                    $('.aboutItem2').off("click").on("click", function (ev) {
                                        ev.stopPropagation();
                                        $(".rainInput").val($(this).html());
                                        $(this).addClass("active").siblings().removeClass("active")
                                    });
                                    $('.aboutItem3').off("click").on("click", function (ev) {
                                        ev.stopPropagation();
                                        $(".snowInput").val($(this).html());
                                        $(this).addClass("active").siblings().removeClass("active")
                                    });
                                    $('.aboutItem4').off("click").on("click", function (ev) {
                                        ev.stopPropagation();
                                        $(".otherInput").val($(this).html());
                                        $(this).addClass("active").siblings().removeClass("active")
                                    });
                                    $('.cloudOK').off("click").on("click", function () {
                                        that.html($(".cloudInput").val());
                                        $(".n-single-table").find('td.editTd').find('div.wp.n-tabler-body-cell-editer-act').each(function () {
                                            $(this).html($(".cloudInput").val());
                                            var copyData = new Array;
                                            copyData = $(this).attr("id").split("_");
                                            var str = copyData[0] + "_2_" + copyData[2];
                                            $("#" + str).html(weatherUtil.getVal($(this).html()));
                                        });
                                        $(".warning-analysis-container").remove();
                                    });
                                    $('.cloudCancel').off("click").on("click", function () {
                                        $(".cloudInput").val("");
                                        $(".warning-analysis-container").remove();
                                    });
                                    $('.rainOK').off("click").on("click", function () {
                                        that.html($(".rainInput").val());
                                        $(".n-single-table").find('td.editTd').find('div.wp.n-tabler-body-cell-editer-act').each(function () {
                                            $(this).html($(".rainInput").val());
                                            var copyData = new Array;
                                            copyData = $(this).attr("id").split("_");
                                            var str = copyData[0] + "_2_" + copyData[2];
                                            $("#" + str).html(weatherUtil.getVal($(this).html()));
                                        });
                                        $(".warning-analysis-container").remove();
                                    });
                                    $('.rainCancel').off("click").on("click", function () {
                                        $(".rainInput").val("");
                                        $(".warning-analysis-container").remove();
                                    });
                                    $('.snowOK').off("click").on("click", function () {
                                        that.html($(".snowInput").val());
                                        $(".n-single-table").find('td.editTd').find('div.wp.n-tabler-body-cell-editer-act').each(function () {
                                            $(this).html($(".snowInput").val());
                                            var copyData = new Array;
                                            copyData = $(this).attr("id").split("_");
                                            var str = copyData[0] + "_2_" + copyData[2];
                                            $("#" + str).html(weatherUtil.getVal($(this).html()));
                                        });
                                        $(".warning-analysis-container").remove();
                                    });
                                    $('.snowCancel').off("click").on("click", function () {
                                        $(".snowInput").val("");
                                        $(".warning-analysis-container").remove();
                                    });
                                    $('.otherOK').off("click").on("click", function () {
                                        that.html($(".otherInput").val());
                                        $(".n-single-table").find('td.editTd').find('div.wp.n-tabler-body-cell-editer-act').each(function () {
                                            $(this).html($(".otherInput").val());
                                            var copyData = new Array;
                                            copyData = $(this).attr("id").split("_");
                                            var str = copyData[0] + "_2_" + copyData[2];
                                            $("#" + str).html(weatherUtil.getVal($(this).html()));
                                        });
                                        $(".warning-analysis-container").remove();
                                    });
                                    $('.otherCancel').off("click").on("click", function () {
                                        $(".otherInput").val("");
                                        $(".warning-analysis-container").remove();
                                    });
                                    $(".warning-analysis-container").off("click").on("click", function (ev) {
                                        ev.stopPropagation();
                                    });
                                    $('.cloudInput').keyup(function () {
                                        var str = "";
                                        var inVal = $.trim($(this).val());
                                        if (inVal == "") {
                                            for (var i = 0; i < gdybProduct.aboutCloud.length; i++) {
                                                str += '<div class="aboutItem1">' + gdybProduct.aboutCloud[i] + '</div>';
                                            }
                                        } else {
                                            for (var i = 0; i < gdybProduct.aboutCloud.length; i++) {
                                                if (gdybProduct.aboutCloud[i].indexOf(inVal) > -1) {
                                                    str += '<div class="aboutItem1">' + gdybProduct.aboutCloud[i] + '</div>';
                                                }
                                            }
                                        }
                                        $(".cloudDiv").html(str);
                                    });
                                    $('.rainInput').keyup(function () {
                                        var str = "";
                                        var inVal = $.trim($(this).val());
                                        if (inVal == "") {
                                            for (var i = 0; i < gdybProduct.aboutRain.length; i++) {
                                                str += '<div class="aboutItem2">' + gdybProduct.aboutRain[i] + '</div>';
                                            }
                                        } else {
                                            for (var i = 0; i < gdybProduct.aboutRain.length; i++) {
                                                if (gdybProduct.aboutRain[i].indexOf(inVal) > -1) {
                                                    str += '<div class="aboutItem2">' + gdybProduct.aboutRain[i] + '</div>';
                                                }
                                            }
                                        }
                                        $(".rainDiv").html(str);
                                    });
                                    $('.snowInput').keyup(function () {
                                        var str = "";
                                        var inVal = $.trim($(this).val());
                                        if (inVal == "") {
                                            for (var i = 0; i < gdybProduct.aboutSnow.length; i++) {
                                                str += '<div class="aboutItem3">' + gdybProduct.aboutSnow[i] + '</div>';
                                            }
                                        } else {
                                            for (var i = 0; i < gdybProduct.aboutSnow.length; i++) {
                                                if (gdybProduct.aboutSnow[i].indexOf(inVal) > -1) {
                                                    str += '<div class="aboutItem3">' + gdybProduct.aboutSnow[i] + '</div>';
                                                }
                                            }
                                        }
                                        $(".snowDiv").html(str);
                                    });
                                    $('.otherInput').keyup(function () {
                                        var str = "";
                                        var inVal = $.trim($(this).val());
                                        if (inVal == "") {
                                            for (var i = 0; i < gdybProduct.aboutOther.length; i++) {
                                                str += '<div class="aboutItem4">' + gdybProduct.aboutOther[i] + '</div>';
                                            }
                                        } else {
                                            for (var i = 0; i < gdybProduct.aboutOther.length; i++) {
                                                if (gdybProduct.aboutOther[i].indexOf(inVal) > -1) {
                                                    str += '<div class="aboutItem4">' + gdybProduct.aboutOther[i] + '</div>';
                                                }
                                            }
                                        }
                                        $(".otherDiv").html(str);
                                    });
                                    $(".multiple-item").off("click").on("click", function () {
                                        that.html($(this).html());
                                        var copyData = new Array;
                                        copyData = that.attr("id").split("_");
                                        var str = copyData[0] + "_2_" + copyData[2];
                                        $("#" + str).html(weatherUtil.getVal($(this).html()));
                                        var dataStr = $(this).html();
                                        $(".n-single-table").find('td.editTd').find('div.wp.n-tabler-body-cell-editer-act').each(function () {
                                            $(this).html(dataStr);
                                            var copyData = new Array;
                                            copyData = $(this).attr("id").split("_");
                                            var str = copyData[0] + "_2_" + copyData[2];
                                            $("#" + str).html(weatherUtil.getVal($(this).html()));
                                        });
                                        //gdybProduct.clearPop();
                                    });

                                    //div可拖拽移动
                                    $(".analysistab").mousedown(function (event) {
                                        // debugger;
                                        var isMove = true;
                                        var _this = $(".warning-analysis-container");
                                        $(this).css({ "cursor": "pointer" }); //点击鼠标切换为手势图形
                                        var m_x = Number(_this.css("left").split("px")[0]); //点击窗体时，left
                                        var m_y;
                                        var bottomFlag = false;
                                        if (_this.css("top").indexOf("px") == -1) {
                                            m_y = Number(_this.css("bottom").split("px")[0]); //点击窗体时，top
                                            bottomFlag = true;
                                        } else {
                                            m_y = Number(_this.css("top").split("px")[0]); //点击窗体时，top
                                        }
                                        var abs_x = event.pageX; //点击窗体时，左边距
                                        var abs_y = event.pageY; //点击窗体时，上边距
                                        //单击住头部可进行拖拽，计算移动大小，以及移动范围限制
                                        $(document).off('mousemove').on('mousemove', function (event) {
                                            if (isMove) {
                                                if (bottomFlag) {
                                                    //event.pageX,移动后的左边距;event.pageY,移动后的上边距
                                                    var ebs_x = m_x - (abs_x - event.pageX); //移动后的left
                                                    var ebs_y = m_y - (event.pageY - abs_y); //移动后的top

                                                    var body_w = $("body").width();
                                                    var body_h = $("body").height();
                                                    var div_w = _this.width();
                                                    var div_h = _this.height();
                                                    //不可超出左右边框
                                                    if (ebs_x <= 0) {
                                                        ebs_x = 0;
                                                    } else if (ebs_x > body_w - div_w) {
                                                        ebs_x = body_w - div_w;
                                                    } else {

                                                    }
                                                    //不可超出上下边框
                                                    if (ebs_y <= 0) {
                                                        ebs_y = 0;
                                                    } else if (ebs_y > body_h - div_h - 50) {
                                                        ebs_y = body_h - div_h - 50;
                                                    } else {

                                                    }
                                                    //重新设定弹出框的左边距，上边距
                                                    _this.css({ 'left': ebs_x, 'bottom': ebs_y });
                                                } else {
                                                    //event.pageX,移动后的左边距;event.pageY,移动后的上边距
                                                    var ebs_x = m_x - (abs_x - event.pageX); //移动后的left
                                                    var ebs_y = bottomFlag ? (m_y - (event.pageY - abs_y)) : (m_y + (event.pageY - abs_y)); //移动后的top

                                                    var body_w = $("body").width();
                                                    var body_h = $("body").height();
                                                    var div_w = _this.width();
                                                    var div_h = _this.height();
                                                    //不可超出左右边框
                                                    if (ebs_x <= 0) {
                                                        ebs_x = 0;
                                                    } else if (ebs_x > body_w - div_w) {
                                                        ebs_x = body_w - div_w;
                                                    } else {

                                                    }
                                                    //不可超出上下边框
                                                    if (ebs_y <= 0) {
                                                        ebs_y = 0;
                                                    } else if (ebs_y > body_h - div_h) {
                                                        ebs_y = body_h - div_h;
                                                    } else {

                                                    }
                                                    //重新设定弹出框的左边距，上边距
                                                    _this.css({ 'left': ebs_x, 'top': ebs_y });
                                                }
                                            }
                                        })
                                    }).mouseup(function () {
                                        isMove = false;
                                        $(document).off('mousemove');
                                        $(".insert_box_title").css("cursor", "default");
                                    }); //鼠标移除事件；单击事件结束事件。;




                                    $('#tmpinput').blur(function () {
                                        var inVal = $(this).val();
                                        if (inVal == "--") {
                                            inVal = "";
                                        }
                                        if (inVal == "") {
                                            that.html("--");
                                        } else {
                                            /*
                                            var copyData = new Array;
                                            copyData = that.attr("id").split("_");
                                            var str = copyData[0]+"_tMax_"+copyData[2];
                                            */
                                            var value = $(this).val().trim();
                                            that.html(value);
                                            $(".n-single-table").find('td.editTd').find('div.wp.n-tabler-body-cell-editer-act').each(function () {
                                                $(this).html(value);
                                                var copyData = new Array;
                                                copyData = $(this).attr("id").split("_");
                                                var str = copyData[0] + "_2_" + copyData[2];
                                                $("#" + str).html(weatherUtil.getVal($(this).html()));
                                            });
                                            var copyData = new Array;
                                            copyData = that.attr("id").split("_");
                                            var str = copyData[0] + "_2_" + copyData[2];
                                            if ($(this).html())
                                                $("#" + str).html(weatherUtil.getVal($(this).html()));
                                        }
                                        return false;
                                    });
                                }
                            } else if (that.attr("class").substr(0, 4) == "rain") {
                                var that = $(this);
                                if (that.find('input').length == 0) {
                                    if (that.html() == "--") {
                                        that.html("<input type=\"text\" id=\"tmpinput\" value=\"\" />");
                                    } else {
                                        that.html("<input type=\"text\" id=\"tmpinput\" value=\"" + that.html() + "\" />");
                                    }
                                    $('#tmpinput').select();
                                    $('#tmpinput').css('color', 'black');

                                    var str = "<ul class=\"multiple-wrap\" style=\"top:" + top + "px;left:" + left + "px;display: block;\">";
                                    var cnt = "";
                                    for (var i = 1; i < 8; i++) {
                                        if (i < 10) {
                                            cnt = "0" + i;
                                        } else {
                                            cnt = i + "";
                                        }
                                        $.each(gdybProduct.getrain, function (k, val) {
                                            if (k == cnt) {
                                                str += "<li class=\"multiple-item\" data-code=\"" + k + "\" title=\"" + val + "\">" + val + "</li>";
                                            }
                                        });
                                    }
                                    str += "</ul>";
                                    $(this).after(str);
                                    $(".multiple-item").off("click").on("click", function () {
                                        that.html($(this).html());
                                        var dataStr = $(this).html();
                                        $(".n-single-table").find('td.editTd').find('div.rain.n-tabler-body-cell-editer-act').each(function () {
                                            $(this).html(dataStr);
                                        });
                                        //gdybProduct.clearPop();
                                    });

                                    $('#tmpinput').blur(function () {
                                        var inVal = $(this).val();
                                        if (inVal == "--") {
                                            inVal = "";
                                        }
                                        if (inVal == "") {
                                            that.html("--");
                                        } else {
                                            var copyData = new Array;
                                            copyData = that.attr("id").split("_");
                                            var str = copyData[0] + "_tMax_" + copyData[2];
                                            var value = $(this).val().trim();
                                            that.html(value);
                                            $(".n-single-table").find('td.editTd').find('div.rain.n-tabler-body-cell-editer-act').each(function () {
                                                $(this).html(value);
                                            });
                                        }
                                        return false;
                                    });
                                }
                            } else if (that.attr("class").substr(0, 2) == "wd") {
                                var that = $(this);
                                if (that.find('input').length == 0) {
                                    if (that.html() == "--") {
                                        that.html("<input type=\"text\" id=\"tmpinput\" value=\"\" />");
                                    } else {
                                        that.html("<input type=\"text\" id=\"tmpinput\" value=\"" + that.html() + "\" />");
                                    }
                                    $('#tmpinput').select();
                                    $('#tmpinput').css('color', 'black');

                                    var str = "<ul class=\"multiple-wrap\" id=\"checkData\" name=\"\" style=\"top:" + top + "px;left:" + left + "px;display: block;\">";
                                    var cnt = "";
                                    for (var i = 1; i < 17; i++) {
                                        if (i < 10) {
                                            cnt = "0" + i;
                                        } else {
                                            cnt = i + "";
                                        }
                                        $.each(gdybProduct.getwd, function (k, val) {
                                            if (k == cnt) {
                                                str += "<li class=\"multiple-item\" data-code=\"" + k + "\" title=\"" + val + "\">" + val + "</li>";
                                            }
                                        });
                                    }
                                    str += "</ul>";
                                    $(this).after(str);
                                    $(".multiple-item").off("click").on("click", function (ev) {
                                        $(this).addClass("active").siblings().removeClass("active");
                                        ev.stopPropagation();
                                        //console.log(that.html());
                                        var found = false;
                                        var str = "";
                                        if ($("#checkData").attr("name") == "") {
                                            if ($(this).html() != "转") {
                                                str = $(this).html();
                                            }
                                        } else {
                                            if ($("#checkData").attr("name").indexOf("转") > -1) {
                                                str = $("#checkData").attr("name") + $(this).html();
                                                found = true;
                                            } else {
                                                if ($(this).html() == "转") {
                                                    str = $("#checkData").attr("name") + $(this).html();
                                                } else {
                                                    str = $(this).html();
                                                }
                                            }
                                        }
                                        $("#checkData").attr("name", str);
                                        that.html(str);
                                        $(".n-single-table").find('td.editTd').find('div.wd.n-tabler-body-cell-editer-act').each(function () {
                                            $(this).html(str);
                                        });
                                        if (found) {
                                            gdybProduct.clearPop();
                                        }
                                        /*
                                        if( $("#checkData").attr("name") == "" ){
                                        	if( $(this).html() != "转" ){
                                        		str = $(this).html();
                                        	}
                                        }else{
                                        	if( that.html().indexOf("转") > -1 ){
                                        		that.html(that.html()+$(this).html());
                                        		//gdybProduct.clearPop();
                                        	}else{
                                        		if( $(this).html() == "转" ){
                                        			that.html(that.html()+$(this).html());
                                        		}else{
                                        			that.html($(this).html());
                                        		}
                                        	}
                                        }
                                        */
                                        //that.html($(this).html());
                                        var dataStr = $(this).html();
                                        $(".n-single-table").find('td.editTd').find('div.wd.n-tabler-body-cell-editer-act').each(function () {
                                            console.log($(this).html());
                                            console.log(dataStr);
                                            //dataStr = $(this).html() + dataStr;
                                            //$(this).html(dataStr);
                                            /*
                                            if( $(this).html().indexOf("转") > -1 ){
                                            	dataStr = $(this).html() + dataStr;
                                            	$(this).html(dataStr);
                                            	gdybProduct.clearPop();
                                            }else{
                                            	if( $(this).html() == "" ){
                                            		if( dataStr == "转" ){
                                            			$(this).html("");
                                            		}else{
                                            			dataStr = $(this).html() + dataStr;
                                            			$(this).html(dataStr);
                                            		}
                                            	}else{
                                            		if( dataStr == "转" ){
                                            			dataStr = $(this).html() + dataStr;
                                            			$(this).html(dataStr);
                                            		}else{
                                            			dataStr = $(this).html() + dataStr;
                                            			$(this).html(dataStr);
                                            		}
                                            	}
                                            }
                                            */
                                        });
                                        //gdybProduct.clearPop();
                                    });

                                    $('#tmpinput').blur(function () {
                                        var inVal = $(this).val();
                                        if (inVal == "--") {
                                            inVal = "";
                                        }
                                        if (inVal == "") {
                                            that.html("--");
                                        } else {
                                            var copyData = new Array;
                                            copyData = that.attr("id").split("_");
                                            var str = copyData[0] + "_tMax_" + copyData[2];
                                            var value = $(this).val().trim();
                                            that.html(value);
                                            $(".n-single-table").find('td.editTd').find('div.wd.n-tabler-body-cell-editer-act').each(function () {
                                                $(this).html(value);
                                            });
                                        }
                                        return false;
                                    });
                                }
                            } else if (that.attr("class").substr(0, 2) == "ws") {
                                var that = $(this);
                                if (that.find('input').length == 0) {
                                    if (that.html() == "--") {
                                        that.html("<input type=\"text\" id=\"tmpinput\" value=\"\" />");
                                    } else {
                                        that.html("<input type=\"text\" id=\"tmpinput\" value=\"" + that.html() + "\" />");
                                    }
                                    $('#tmpinput').select();
                                    $('#tmpinput').css('color', 'black');

                                    var str = "<div class=\"multiple-wrap2\" style=\"top:" + top + "px;left:" + left + "px;display: block;\">";
                                    str += "<input type='button' name='0' class='gust' value='阵风' />";
                                    str += "<ul class=\"multiple-wrap3\">";
                                    var cnt = "";
                                    for (var i = 1; i < 27; i++) {
                                        if (i < 10) {
                                            cnt = "0" + i;
                                        } else {
                                            cnt = i + "";
                                        }
                                        $.each(gdybProduct.getws, function (k, val) {
                                            if (k == cnt) {
                                                str += "<li class=\"multiple-item\" data-code=\"" + k + "\" title=\"" + val + "\">" + val + "</li>";
                                            }
                                        });
                                    }
                                    str += "</ul>";
                                    str += "</div>";
                                    $(this).after(str);
                                    $(".gust").off("click").on("click", function (ev) {
                                        ev.stopPropagation();
                                        if ($(this).attr("name") == "0") {
                                            $(this).attr("name", "1");
                                            var cnt = "";
                                            var str2 = "";
                                            for (var i = 1; i < 27; i++) {
                                                if (i < 10) {
                                                    cnt = "0" + i;
                                                } else {
                                                    cnt = i + "";
                                                }
                                                $.each(gdybProduct.getws, function (k, val) {
                                                    if (k == cnt) {
                                                        str2 += "<li class=\"multiple-item\" data-code=\"" + k + "\" title=\"" + val + gdybProduct.getws2[i - 1] + "\">" + val + gdybProduct.getws2[i - 1] + "</li>";
                                                    }
                                                });
                                            }
                                            $(".multiple-wrap3").html(str2);
                                        } else {
                                            $(this).attr("name", "0");
                                            var cnt = "";
                                            var str2 = "";
                                            for (var i = 1; i < 27; i++) {
                                                if (i < 10) {
                                                    cnt = "0" + i;
                                                } else {
                                                    cnt = i + "";
                                                }
                                                $.each(gdybProduct.getws, function (k, val) {
                                                    if (k == cnt) {
                                                        str2 += "<li class=\"multiple-item\" data-code=\"" + k + "\" title=\"" + val + "\">" + val + "</li>";
                                                    }
                                                });
                                            }
                                            $(".multiple-wrap3").html(str2);
                                        }
                                        $(".multiple-item").off("click").on("click", function () {
                                            that.html($(this).html());
                                            var dataStr = $(this).html();
                                            $(".n-single-table").find('td.editTd').find('div.ws.n-tabler-body-cell-editer-act').each(function () {
                                                $(this).html(dataStr);
                                            });
                                            //gdybProduct.clearPop();
                                            $(".n-single-table").find('td.editTd').find('div.ws.n-tabler-body-cell-editer-act').each(function () {
                                                if ($(this).attr("id").substr(0, 7) == "yb13_4_") {
                                                    var tmp = -1;
                                                    var tmp2 = "";
													$.each(gdybProduct.getws, function (k, val) {
														if (that.html().indexOf(val) != -1) {
															tmp = k;
														}
													});
                                                    tmp = parseInt(tmp);
													if (tmp <= 1) tmp = 4;
													else tmp += 2;
                                                    if (tmp < 10) {
                                                        tmp = "0" + tmp + "";
                                                    } else {
                                                        tmp = tmp + "";
                                                    }
                                                    $.each(gdybProduct.getws, function (k, val) {
                                                        if (k == tmp) {
                                                            tmp2 = val;
                                                        }
                                                    });
                                                    var copyData = new Array;
                                                    copyData = that.attr("id").split("_");
                                                    var str = "yb14_" + copyData[1] + "_" + copyData[2];
                                                    $("#" + str).html(tmp2);
                                                }
                                            });
                                            if (that.attr("id").substr(0, 7) == "yb13_4_") {
                                                var tmp = -1;
                                                var tmp2 = "";
												$.each(gdybProduct.getws, function (k, val) {
													if (that.html().indexOf(val) != -1) {
														tmp = k;
													}
												});
                                                tmp = parseInt(tmp);
												if (tmp <= 1) tmp = 4;
												else tmp += 2;
                                                if (tmp < 10) {
                                                    tmp = "0" + tmp + "";
                                                } else {
                                                    tmp = tmp + "";
                                                }
                                                $.each(gdybProduct.getws, function (k, val) {
                                                    if (k == tmp) {
                                                        tmp2 = val;
                                                    }
                                                });
                                                var copyData = new Array;
                                                copyData = that.attr("id").split("_");
                                                var str = "yb14_" + copyData[1] + "_" + copyData[2];
                                                $("#" + str).html(tmp2);
                                            }
                                        });
                                    });
                                    $(".multiple-item").off("click").on("click", function () {
                                        that.html($(this).html());
                                        var dataStr = $(this).html();
                                        $(".n-single-table").find('td.editTd').find('div.ws.n-tabler-body-cell-editer-act').each(function () {
                                            $(this).html(dataStr);
                                        });
                                        //gdybProduct.clearPop();
                                        $(".n-single-table").find('td.editTd').find('div.ws.n-tabler-body-cell-editer-act').each(function () {
                                            if ($(this).attr("id").substr(0, 7) == "yb13_4_") {
                                                var tmp = -1;
                                                var tmp2 = "";
												$.each(gdybProduct.getws, function (k, val) {
													if (that.html() == val) {
														tmp = k;
													}
												});
                                                tmp = parseInt(tmp);
												if (tmp <= 1) tmp = 4;
												else tmp += 2;
                                                if (tmp < 10) {
                                                    tmp = "0" + tmp + "";
                                                } else {
                                                    tmp = tmp + "";
                                                }
                                                $.each(gdybProduct.getws, function (k, val) {
                                                    if (k == tmp) {
                                                        tmp2 = val;
                                                    }
                                                });
                                                var copyData = new Array;
                                                copyData = that.attr("id").split("_");
                                                var str = "yb14_" + copyData[1] + "_" + copyData[2];
                                                $("#" + str).html(tmp2);
                                            }
                                        });
                                        if (that.attr("id").substr(0, 7) == "yb13_4_") {
                                            var tmp = -1;
                                            var tmp2 = "";
											$.each(gdybProduct.getws, function (k, val) {
												if (that.html() == val) {
													tmp = k;
												}
											});
                                            tmp = parseInt(tmp);
											if (tmp <= 1) tmp = 4;
											else tmp += 2;
                                            if (tmp < 10) {
                                                tmp = "0" + tmp + "";
                                            } else {
                                                tmp = tmp + "";
                                            }
                                            $.each(gdybProduct.getws, function (k, val) {
                                                if (k == tmp) {
                                                    tmp2 = val;
                                                }
                                            });
                                            var copyData = new Array;
                                            copyData = that.attr("id").split("_");
                                            var str = "yb14_" + copyData[1] + "_" + copyData[2];
                                            $("#" + str).html(tmp2);
                                        }
                                    });

                                    $('#tmpinput').blur(function () {
                                        var inVal = $(this).val();
                                        if (inVal == "--") {
                                            inVal = "";
                                        }
                                        if (inVal == "") {
                                            that.html("--");
                                        } else {
                                            var copyData = new Array;
                                            copyData = that.attr("id").split("_");
                                            var str = copyData[0] + "_tMax_" + copyData[2];
                                            var value = $(this).val().trim();
                                            that.html(value);
                                            $(".n-single-table").find('td.editTd').find('div.ws.n-tabler-body-cell-editer-act').each(function () {
                                                $(this).html(value);
                                            });
                                        }
                                        return false;
                                    });
                                }
                            } else if (that.attr("class").substr(0, 4) == "tmax") {
                                //gdybProduct.clearPop();
                                var that = $(this);
                                if (that.find('input').length == 0) {
                                    if (that.html() == "--") {
                                        that.html("<input type=\"text\" id=\"tmpinput\" value=\"\" />");
                                    } else {
                                        that.html("<input type=\"text\" id=\"tmpinput\" value=\"" + that.html() + "\" />");
                                    }
                                    $('#tmpinput').select();
                                    $('#tmpinput').css('color', 'black');
                                    $('#tmpinput').blur(function () {
                                        var inVal = $(this).val();
                                        if (inVal == "--") {
                                            inVal = "";
                                        }
                                        if (inVal == "") {
                                            that.html("--");
                                        } else {
                                            inVal = parseFloat(inVal, 10);
                                            if (reg.test(inVal) && (inVal < 100)) {
                                                var copyData = new Array;
                                                copyData = that.attr("id").split("_");
                                                var str = copyData[0] + "_tMax_" + copyData[2];
                                                if (($("#" + str).html() != "--") && ($("#" + str).html() != "")) {
                                                    if (inVal > parseFloat($("#" + str).html(), 10)) {
                                                        $('#tmpinput').css('outline-color', 'red').select();
                                                        return false;
                                                    }
                                                }
                                                var value = $(this).val().trim();
                                                that.html(value);
                                                $(".n-single-table").find('td.editTd').find('div.tmax.n-tabler-body-cell-editer-act').each(function () {
                                                    $(this).html(value);
                                                });
                                            } else {
                                                $('#tmpinput').css('outline-color', 'red').select();
                                            }
                                        }
                                        return false;
                                    });
                                }
                            } else if (that.attr("class").substr(0, 4) == "tmin") {
                                //gdybProduct.clearPop();
                                var that = $(this);
                                if (that.find('input').length == 0) {
                                    if (that.html() == "--") {
                                        that.html("<input type=\"text\" id=\"tmpinput\" value=\"\" />");
                                    } else {
                                        that.html("<input type=\"text\" id=\"tmpinput\" value=\"" + that.html() + "\" />");
                                    }
                                    $('#tmpinput').select();
                                    $('#tmpinput').css('color', 'black');
                                    $('#tmpinput').blur(function () {
                                        var inVal = $(this).val();
                                        if (inVal == "--") {
                                            inVal = "";
                                        }
                                        if (inVal == "") {
                                            that.html("--");
                                        } else {
                                            inVal = parseFloat(inVal, 10);
                                            if (reg.test(inVal) && (inVal > -100)) {
                                                var copyData = new Array;
                                                copyData = that.attr("id").split("_");
                                                var str = copyData[0] + "_tMax_" + copyData[2];
                                                if (($("#" + str).html() != "--") && ($("#" + str).html() != "")) {
                                                    if (inVal > parseFloat($("#" + str).html(), 10)) {
                                                        $('#tmpinput').css('outline-color', 'red').select();
                                                        return false;
                                                    }
                                                }
                                                var value = $(this).val().trim();
                                                that.html(value);
                                                $(".n-single-table").find('td.editTd').find('div.tmin.n-tabler-body-cell-editer-act').each(function () {
                                                    $(this).html(value);
                                                });
                                            } else {
                                                $('#tmpinput').css('outline-color', 'red').select();
                                            }
                                        }
                                        return false;
                                    });
                                }
                            } else if (that.attr("class").substr(0, 4) == "smax") {
                                //gdybProduct.clearPop();
                                var that = $(this);
                                if (that.find('input').length == 0) {
                                    if (that.html() == "--") {
                                        that.html("<input type=\"text\" id=\"tmpinput\" value=\"\" />");
                                    } else {
                                        that.html("<input type=\"text\" id=\"tmpinput\" value=\"" + that.html() + "\" />");
                                    }
                                    $('#tmpinput').select();
                                    $('#tmpinput').css('color', 'black');
                                    $('#tmpinput').blur(function () {
                                        var inVal = $(this).val();
                                        if (inVal == "--") {
                                            inVal = "";
                                        }
                                        if (inVal == "") {
                                            that.html("--");
                                        } else {
                                            var copyData = new Array;
                                            copyData = that.attr("id").split("_");
                                            var str = copyData[0] + "_tMax_" + copyData[2];
                                            var value = $(this).val().trim();
                                            that.html(value);
                                            $(".n-single-table").find('td.editTd').find('div.smax.n-tabler-body-cell-editer-act').each(function () {
                                                $(this).html(value);
                                            });
                                        }
                                        return false;
                                    });
                                }
                            } else if (that.attr("class").substr(0, 4) == "smin") {
                                var that = $(this);
                                if (that.find('input').length == 0) {
                                    debugger
                                    if (initalVal == "--") {
                                        that.html("<input type=\"text\" id=\"tmpinput\" value=\"\" />");
                                    } else {
                                        that.html("<input type=\"text\" id=\"tmpinput\" value=\"" + initalVal + "\" />");
                                    }
                                    that.find('#tmpinput').select();
                                    that.find('#tmpinput').css('color', 'black');
                                    that.find('#tmpinput').blur(function () {
                                        var inVal = $(this).val();
                                        if (inVal == "--") {
                                            inVal = "";
                                        }
                                        if (inVal == "") {
                                            that.html("--");
                                        } else {
                                            debugger
                                            var copyData = new Array;
                                            copyData = that.attr("id").split("_");
                                            var str = copyData[0] + "_tMax_" + copyData[2];
                                            var value = $(this).val().trim();
                                            that.html(value);
                                            $(".n-single-table").find('td.editTd').find('div.smin.n-tabler-body-cell-editer-act').each(function () {
                                                $(this).html(value);
                                            });
                                        }
                                        return false;
                                    });
                                }
                            }
                            if(that[0].nextSibling){
                                var containerHeight = that[0].nextSibling.offsetHeight;
                                if (trTop + containerHeight > tableHeight) {
                                    $(that[0].nextSibling).css("top", (0 - containerHeight) + "px");
                                }
                            }

                        }
                    });
                }
            } else if ((cnt == "i_gdyb01_msg02") || (cnt == "i_gdyb02_msg02") || (cnt == "i_gdyb03_msg02")) {
                $(".warnGdyb").val(jsonStr.tempData.curTagData[cnt].val);
            }
        }
		$(".n-single-table tr div").mousedown(function (e) {
			e.preventDefault();
			if ($(this).parent().parent().index() != that.currTrIndex || that.currTrIndex === -1) {
				that.selected = [];
				$('.n-tabler-body-cell-editer-act').removeClass('n-tabler-body-cell-editer-act');
			}
			that.selected.push($(this).attr('id'));
			$(this).addClass('n-tabler-body-cell-editer-act');

			that.currTrIndex = $(this).parent().parent().index();

		}).click(function (e) {
			e.preventDefault();
			if (e.target.children.length > 0)
				return false;
		})
		$(".n-single-table tr").mousedown(function (e) {
			$(this).find('div').unbind('mouseenter').mouseenter(function (e) {
				e.stopPropagation();
				e.preventDefault();
				var index = that.selected.indexOf($(this).attr('id'));
				if (index < 0) {
					that.selected.push($(this).attr('id'));
					$(this).addClass('n-tabler-body-cell-editer-act');
				} else {
					//delete selected[index];
					//$(this).removeClass('n-tabler-body-cell-editer-act');
				}
			})
			//return false;
		}).mouseup(function (e) {
			e.preventDefault();
			e.stopPropagation();
			if (that.deleteSameArr(that.selected).length === 1) {
				that.currTrIndex = -1;
			}
			$(".n-single-table tr td div").unbind("mouseenter");
		}).click(function (e) {
			e.preventDefault();
			if (e.target.children.length > 0)
				return false;
		});
		$(".n-single-table .element").click(function(e){
			$(this).parent().siblings('tr').find('>td>div').removeClass('n-tabler-body-cell-editer-act');
			$(this).parent().find('>td>div').each(function(){
				$(this).addClass('n-tabler-body-cell-editer-act');
				that.selected.push($(this).attr('id'));
			})
			that.currTrIndex = $(this).parent().index();
			e.preventDefault();
			e.stopPropagation();
		})
		$('.div-content').unbind('click').bind('click', function (e) {
			gdybProduct.clearPop();
		}).mouseup(function (e) {
			$(".n-single-table tr td div").unbind("mouseenter");
		});
    },
    deleteSameArr: function (arr) {
        var arr1 = [];
        for (var i = 0; i < arr.length; i++) {
            if (arr1.indexOf(arr[i]) === -1) {
                arr1.push(arr[i]);
            }
        }
        return arr1;
    },
    getTr: function (cnt, arr) {
        var str = "";
        var tmp = "";
        var tmp2 = ""
        let color = cnt%2 == 0?'#fff !important':'#e6f4ff !important'
        for (var i = 0; i < arr.length; i++) {
            str += "<tr>";
            if (i == 0) {
                str += "<td width='210px' style='background:"+color+"' class='yb03_0_" + cnt + "' rowspan='" + arr.length + "'></td>";
            }
            str += "<td style='background:"+color+"' class='element' width='180px'>" + arr[i] + "</td>";

            if (arr[i] == "天气现象") {
                tmp2 = "wp";
            } else if (arr[i] == "降水概率") {
                tmp2 = "rain";
            } else if (arr[i] == "降水概率") {
                tmp2 = "rain";
            } else if (arr[i] == "风向") {
                tmp2 = "wd";
            } else if (arr[i] == "风速") {
                tmp2 = "ws";
            } else if (arr[i] == "高温") {
                tmp2 = "tmax";
            } else if (arr[i] == "低温") {
                tmp2 = "tmin";
            } else if (arr[i] == "最大相对湿度") {
                tmp2 = "smax";
            } else if (arr[i] == "最小相对湿度") {
                tmp2 = "smin";
            } else {
                tmp2 = "";
            }

            tmp = (i + 1) + "_" + cnt;

            str += "<td class='editTd borderset' style='background:"+color+"' width='7%'><div class='" + tmp2 + "' id='yb03_" + tmp + "'></div></td>";
            str += "<td class='editTd' style='background:"+color+"' width='7%'><div class='" + tmp2 + "' id='yb04_" + tmp + "'></div></td>";
            str += "<td class='editTd' style='background:"+color+"' width='7%'><div class='" + tmp2 + "' id='yb05_" + tmp + "'></div></td>";
            str += "<td class='editTd borderset' style='background:"+color+"' width='7%'><div class='" + tmp2 + "' id='yb06_" + tmp + "'></div></td>";
            str += "<td class='editTd' style='background:"+color+"' width='7%'><div class='" + tmp2 + "' id='yb07_" + tmp + "'></div></td>";
            str += "<td class='editTd borderset' style='background:"+color+"' width='7%'><div class='" + tmp2 + "' id='yb08_" + tmp + "'></div></td>";
            str += "<td class='editTd' style='background:"+color+"' width='7%'><div class='" + tmp2 + "' id='yb09_" + tmp + "'></div></td>";
            str += "<td class='editTd' style='background:"+color+"' width='7%'><div class='" + tmp2 + "' id='yb10_" + tmp + "'></div></td>";
            str += "<td class='editTd' style='background:"+color+"' width='7%'><div class='" + tmp2 + "' id='yb11_" + tmp + "'></div></td>";
            str += "<td class='editTd borderset' style='background:"+color+"' width='7%'><div class='" + tmp2 + "' id='yb12_" + tmp + "'></div></td>";
            str += "<td class='editTd' style='background:"+color+"' width='7%'><div class='" + tmp2 + "' id='yb13_" + tmp + "'></div></td>";
            str += "<td class='editTd' style='background:"+color+"' width='7%'><div class='" + tmp2 + "' id='yb14_" + tmp + "'></div></td>";
            str += "</tr>";
        }
        return str;
    },
    rightEvents: function (that, top, left) {
        gdybProduct.clearPop2();
        var html = '<div class="right-menu" style="top:' + top + 'px;left:' + left + 'px;display: block;\"><ul class="right-menu-list">';
        html += '<li class="select-row" name="' + that.attr("id") + "_" + that.attr("name") + '">选择行</li>';
        html += '</ul></div>';
        that.after(html);
        $(".select-row").off("click").on("click", function (ev) {
            ev.stopPropagation();
            gdybProduct.clearPop2();
            var copyData = new Array;
            var copyData2 = new Array;
            copyData = $(this).attr("name").split("_");
            var str = copyData[1] + "_" + copyData[2];
            $(".n-single-table").find('td.editTd').find('div').each(function () {
                if ($(this).attr("id") != undefined) {
                    copyData2 = $(this).attr("id").split("_");
                    if (str == (copyData2[1] + "_" + copyData2[2])) {
                        $(this).addClass('n-tabler-body-cell-editer-act');
                    }
                }
            });
            return false;
        });
    },
    clearPop: function () {
        $(".warning-analysis-container").remove();
        $('.multiple-wrap').remove();
        $('.multiple-wrap2').remove();
        $('.right-menu').remove();
        if ($('input#tmpinput').length > 0) {
            $('input#tmpinput').blur();
        }
        $('.n-tabler-body-cell-editer-act').removeClass('n-tabler-body-cell-editer-act');
    },
    clearPop2: function () {
        $(".warning-analysis-container").remove();
        $('.multiple-wrap').remove();
        $('.multiple-wrap2').remove();
        $('.right-menu').remove();
        if ($('input#tmpinput').length > 0) {
            $('input#tmpinput').parent().html($('input#tmpinput').val())
        }
    },
    bindEvents: function () {
        var that = this;
        $(".confirmBtn").click(function () {
            $("#report_police").click();
            $("#warnVal").show().val(that.getWarnInfo());
        });
        $("#remake_opr").off("click").on("click", function () {
            that.ajaxTable();
        });

        $("#save_opr").off("click").on("click", function () {
            that.saveProductWin();
        });
        $("#publish_opr").off("click").on("click", function () {
            that.publishProductWin();
        });
        $("#preview_opr").off("click").on("click", function (event) {
            event.stopPropagation();
            $(".warning-zxhl-wrap").remove();
            var html = "<div class='warning-zxhl-wrap dragDiv' style='width:800px;height:600px;'>" +
                "<div class='warning-zxhl-title-wrap' style='cursor: default;'>" +
                "<div class='warning-zxhl-title-content'>预览</div>" +
                "<div class='warning-zxhl-title-close'></div>" +
                "</div>" +
                "<div class='viewData'>" +
                "</div>" +
                "</div>";
            $wrap = $(html);
            $("#head_button").append($wrap);
            that.dragDiv($(".warning-zxhl-title-wrap"));
            $wrap.find(".warning-zxhl-title-close").unbind("click").bind("click", function () {
                $(".warning-zxhl-wrap").remove();
            });
            that.previewProductWin();
        });
        //lj_end-------------------------------------------------------------
        //tzl开始-------------------------------------------------------------------------------------

        $(".tool_type").off("click").on("click", function () {
            //				if($(this).find("div").eq(2).text() != "辅助工具"){
            //					return;
            //				}
            if (!$(this).hasClass("tool_type_sel")) {
                $(".tool_type_sel").find("div").eq(0).show();
                $(".tool_type_sel").find("div").eq(1).hide();
                $(".tool_type").removeClass("tool_type_sel");
                $(this).addClass("tool_type_sel");
                $(this).find("div").eq(0).hide();
                $(this).find("div").eq(1).show();
                //
                $(".tool_content").empty();
                //div方式展开
                that.ajaxBusisPage($(this));
            }
        });
        $("#report_police").click(function () {
            $(this).find('i').toggleClass('active');
            $(this).toggleClass('active');
            $(".alarmData").toggleClass("block");
            that.initAlarmData();
        });
        $("#alarmSelect").on('change', function () {
            var val = $(this).val();
            if (val == '15:25') {
                $(".alarmData-content a").text('下午');
            } else {
                $(".alarmData-content a").text('上午');
            }
        })
		document.oncontextmenu = function() {
			return false;
		}
    },
    initAlarmData: function () {
        var productInfo = $(".task-menu-list li.active").data('product');
        var time = { '05:00': '6', '10:15': '11', '15:25': '17' };
        var $select = $("#alarmSelect").empty();
        for (var key in time) {
            if (key == productInfo.fortime) {
                $select.append(`<option selected value="${key}">${time[key]}</option>`);
            } else {
                $select.append(`<option value="${key}">${time[key]}</option>`);
            }
        }
        $select.change();
    },
    //事件拖拽div
    dragDiv: function (titleDiv) {
        //单击弹出框的头部，确定点击处的位置
        $(titleDiv).mousedown(function (event) {
            $(".dragDiv").css({ "z-index": "1" });
            var isMove = true;
            var _this = $(titleDiv).parent();
            _this.css({ "z-index": "10" });
            $(this).css({ "cursor": "move" }); //点击鼠标切换为手势图形
            var m_x = Number(_this.css("left").split("px")[0]); //点击窗体时，left
            var m_y = Number(_this.css("top").split("px")[0]); //点击窗体时，top
            var abs_x = event.pageX; //点击窗体时，左边距
            var abs_y = event.pageY; //点击窗体时，上边距
            //单击住头部可进行拖拽，计算移动大小，以及移动范围限制
            $(document).unbind('mousemove').bind('mousemove', function (event) {
                if (isMove) {
                    //event.pageX,移动后的左边距;event.pageY,移动后的上边距
                    var ebs_x = m_x + (event.pageX - abs_x); //移动后的left
                    var ebs_y = m_y + (event.pageY - abs_y); //移动后的top
                    var body_w = $("body").width();
                    var body_h = $("body").height();
                    var div_w = _this.width();
                    var div_h = _this.height();
                    //不可超出左右边框
                    if (ebs_x <= 0) {
                        ebs_x = 0;
                    } else if (ebs_x > body_w - div_w) {
                        ebs_x = body_w - div_w;
                    } else {

                    }
                    //不可超出上下边框
                    if (ebs_y <= 0) {
                        ebs_y = 0;
                    } else if (ebs_y > body_h - div_h) {
                        ebs_y = body_h - div_h;
                    } else {

                    }
                    //重新设定弹出框的左边距，上边距
                    _this.css({ 'left': ebs_x, 'top': ebs_y });
                }
            }).mouseup(function () {
                isMove = false
                $(document).unbind('mousemove');
                $(titleDiv).css({ "cursor": "default" }); //点击鼠标切换为手势图形
            }); //鼠标移除事件；单击事件结束事件。
        });
    },
    //保存
    saveProductWin: function () {
        var forStr = "";
        if ($(".single_time_click").attr("fortimeid") != undefined) {
            forStr = $(".single_time_click").attr("fortimeid");
        } else {
            forStr = $("#forTime option:selected").attr("fortimeid");
        }
        var cntTable = 12;
        if (forStr == "06:00") {
            cntTable = 6;
        }
        if (forStr == "11:00") {
            cntTable = 8;
        }
        var obj = JSON.parse(gdybProduct.initJson);
        for (var cnt in obj.tempData.curTagData) {
            if ((cnt == "i_gdyb01_msg02") || (cnt == "i_gdyb02_msg02") || (cnt == "i_gdyb03_msg02")) {
                if (!$("#warnVal").val()) {
                    obj.tempData.curTagData[cnt].val = "";
                } else {
                    obj.tempData.curTagData[cnt].val = $("#warnVal").val();
                }
            } else if (cnt.indexOf("h_") != -1) {
                var valStr = "[";
                var tmp = cnt.substr(9);
                for (var i = 0; i < cntTable; i++) {
                    valStr += "[\"";
                    valStr += $(".yb03_0_" + i).html() + "\",";
                    for (var j = 1; j < 7; j++) {
                        if ($("#" + tmp + "_" + j + "_" + i).html() != undefined) {
                            valStr += "\"" + $("#" + tmp + "_" + j + "_" + i).html() + "\"";
                        } else {
                            valStr += "\"\"";
                        }
                        if (j < 6) {
                            valStr += ",";
                        }
                    }
                    valStr += "]";
                    if (i < 11) {
                        valStr += ",";
                    }
                }
                valStr += "]";
                obj.tempData.curTagData[cnt].val = valStr;
            }
        }
        var str = JSON.stringify(obj);
        var params = {
            stationName: this.stationName,
            falg: "save",
            product_id: this.productInfo.productId,
            fortime: this.productInfo.fortime,
            forecasterName: $("#userInfo").data('info').smuser.name,
            forecasterId: $("#userInfo").data('info').smuser.iid,
            jsonStr: str,
			taskId: this.productInfo.taskId
        }
        loading.add('.cafe-container');
        $.ajax({
            url: api.internal.gdyb.saveGdyb,
            data: params,
            type: 'post',
            success: function () {
                loading.remove();
                alert("保存成功!");
            },
            error: function () {
                loading.remove();
                alert("make data error");
            }
        });
    },
    getWarnInfo: function () {
        var str = "";
        $(".alarmData-content").children().each(function () {
            var obj = $(this);
            if (obj.hasClass("val")) {
                str = str + obj.val();
            } else if (obj.hasClass("alarmVal")) {
                str = str + $('.alarmVal option:selected').text();
            } else {
                str = str + obj.text();
            }
        })
        return str;
    },
    //发布
    publishProductWin: function () {
        var forStr = "";
        if ($(".single_time_click").attr("fortimeid") != undefined) {
            forStr = $(".single_time_click").attr("fortimeid");
        } else {
            forStr = $("#forTime option:selected").attr("fortimeid");
        }
        var cntTable = 12;
        if (forStr == "06:00") {
            cntTable = 6;
        }
        if (forStr == "11:00") {
            cntTable = 8;
        }
        var obj = JSON.parse(gdybProduct.initJson);
        for (var cnt in obj.tempData.curTagData) {
            if ((cnt == "i_gdyb01_msg02") || (cnt == "i_gdyb02_msg02") || (cnt == "i_gdyb03_msg02")) {
                if (!$("#warnVal").val()) {
                    obj.tempData.curTagData[cnt].val = "";
                } else {
                    obj.tempData.curTagData[cnt].val = $("#warnVal").val();
                }
            } else if (cnt.indexOf("h_") != -1) {
                var valStr = "[";
                var tmp = cnt.substr(9);
                for (var i = 0; i < cntTable; i++) {
                    valStr += "[\"";
                    valStr += $(".yb03_0_" + i).html() + "\",";
                    for (var j = 1; j < 7; j++) {
                        if ($("#" + tmp + "_" + j + "_" + i).html() != undefined) {
                            valStr += "\"" + $("#" + tmp + "_" + j + "_" + i).html() + "\"";
                        } else {
                            valStr += "\"\"";
                        }
                        if (j < 6) {
                            valStr += ",";
                        }
                    }
                    valStr += "]";
                    if (i < 11) {
                        valStr += ",";
                    }
                }
                valStr += "]";
                obj.tempData.curTagData[cnt].val = valStr;
            }
        }
        var str = JSON.stringify(obj);
        var params = {
            stationName: this.stationName,
            falg: "pub",
            product_id: this.productInfo.productId,
            fortime: this.productInfo.fortime,
            forecasterName: $("#userInfo").data('info').smuser.name,
            forecasterId: $("#userInfo").data('info').smuser.iid,
            jsonStr: str,
			taskId: this.productInfo.taskId
        }
        loading.add('.cafe-container');
        var that = this;
        $.ajax({
            url: api.internal.gdyb.publishGdyb,
            data: params,
            type: 'post',
            success: function () {
                loading.remove();
                CafeJS.menuFunc.setTask();
                alert("发布成功!");
            },
            error: function () {
                loading.remove();
                alert("make data error");
            }
        });
    },
    //预览
    previewProductWin: function () {
        var forStr = "";
        if ($(".single_time_click").attr("fortimeid") != undefined) {
            forStr = $(".single_time_click").attr("fortimeid");
        } else {
            forStr = $("#forTime option:selected").attr("fortimeid");
        }
        var cntTable = 12;
        if (forStr == "06:00") {
            cntTable = 6;
        }
        if (forStr == "11:00") {
            cntTable = 8;
        }
        var params = {
            product_id: this.productInfo.productId,
            fortime: this.productInfo.fortime,
            queryTime: new Date().format('yyyy-MM-dd 00:00:00')
        };
        loading.add('.cafe-container');
        $.getJSON(api.internal.common.getProductDetail, params, function (res) {
            loading.remove();
            if (res.isSuccess) {
                var data = res.data.txtContent;
                if ((data != undefined) && (data != "")) {
                    $(".viewData").html("<textarea readonly style='width:800px;height:600px;'>" + data + "</textarea>");
                } else {
                    $(".viewData").html("<textarea readonly style='width:800px;height:600px;'>暂无可浏览的产品！</textarea>");
                }
            }
        })
    },



    readProductWin: function (data) {
        $.ajax({
            url: G_CONTEXT.contextPath + '/jwb/readData.do',
            data: {
                data: data
            },
            type: 'post',
            dataType: 'json',
            success: function (result) {
                //console.log(result);
                if ((result.params.data != undefined) && (result.params.data != "")) {
                    $(".viewData").html("<textarea readonly style='width:800px;height:600px;'>" + result.params.data + "</textarea>");
                } else {
                    $(".viewData").html("<textarea readonly style='width:800px;height:600px;'>暂无可浏览的产品！</textarea>");
                }
            },
            error: function () {

            }
        });
    },
    initWithHeight: function () {
        $("#box").height($(".dqproduct_main").height() - $(".div-head").height() - 20 - 48);
    },
};
$(function () {
    gdybProduct.init();
});